import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './registerServiceWorker'

Vue.config.productionTip = false

import * as global from './components/func/func'
Vue.prototype.global = global

import 'font-awesome/css/font-awesome.css'
import './components/css/main.scss'

import i18n from './components/lang/index'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

// let MintUI = require('mint-ui')
// import 'mint-ui/lib/style.css'
// Vue.use(MintUI)

let quillEditor = require('vue-quill-editor')
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(quillEditor)

let NProgress = require('nprogress')
import 'nprogress/nprogress.css'

let echarts = require('echarts')
Vue.prototype.$echarts = echarts

//onload
router.beforeEach((to, from, next) => {
  if(to.meta.title){
    document.title = to.meta.title
  }else{
    document.title = 'Sheets'
  }
  let outTime = 1597219091 // '2020-08-12 00:00:00' 早于此时间的为过期状态
  let user = localStorage.getItem('user_id')
  let loginTime = localStorage.getItem('loginTime') || 0
  // let passLink = ['/login','/form']

  if(to.meta.pass){
    NProgress.start();
    next()
  }else{
    if(user && loginTime){
      if(loginTime > outTime){
        NProgress.start()
        next()
      }else{
        ElementUI.Message.warning('登录已过期')
        window.location.href="/login"
      }
    }else{
      ElementUI.Message.warning('还没有登录')
      window.location.href="/login"
    }
  }
});
//end load
router.afterEach(transition => {
  NProgress.done();
});

new Vue({
  router,
  i18n,
  store,
  render: h => h(App)
}).$mount('#app')
